package com.aishang.shopback_2005.intercepter;

import com.aishang.shopback_2005.po.Adminuser;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author a1790
 */
@Component
public class MySessionIntercepter implements HandlerInterceptor {
    @Resource
    private HttpSession session;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        Adminuser adminUser = (Adminuser) session.getAttribute("adminUser");
        if(adminUser!=null){
           return true;
        }else {
            response.getWriter().print("you need login");
            return true;
        }

    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
